<?php
namespace lib\builtin\auth;

use RuntimeException;

class NoPermissionException extends RuntimeException
{
    public function __construct($permissionOrMessage, $isPermission = true)
    {
        if ($isPermission && isset($permissionOrMessage['code'])) {
            $perm = $permissionOrMessage;
            if (isset($perm['text'])) {
                $message = '您没有' . $perm['text'] . '(' . $perm['code'] . ')的权限';
            } else {
                $message = '您没有操作<' . $perm['code'] . '>的权限';
            }
        } else {
            if (is_string($permissionOrMessage)) {
                $message = $permissionOrMessage;
            } else {
                $message = '您无此操作的权限';
            }
        }
        parent::__construct($message);
    }
}
